package com.onstar.cn.api.framework;

import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.network.entity.RequestEntity;

/**
 * Created by 6335yz on 2016/7/8.
 */
public class BaseApiService {
    protected String serverUrl;

    public BaseApiService(String serverUrl) {
        this.serverUrl = serverUrl;
    }

    public RequestEntity getURLRequestEntity(String methodName, String body, Object... params) {
        RequestEntity requsetEntity = null;
        for (Object param : params) {
            if (param instanceof RequestEntity) {
                requsetEntity = (RequestEntity) param;
                break;
            }
        }
        if (requsetEntity == null) {
            requsetEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), methodName, params);
        LogManager.getInstance().d("Request url: " + serverUrl + url);
        requsetEntity.setUrl(serverUrl + url);
        if (!CommonUtil.isNull(body)) {
            requsetEntity.setBody(body);
        }
        return requsetEntity;
    }
}
